﻿using Biz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BusinessLayer.Dal
{
    public class ProductPropertiesDal
    {
        public static void Insert(ProductProperties pp)
        {
            DatabaseContext.DB.ProductProperties.Add(pp);
            DatabaseContext.DB.SaveChanges();
        }

        public static void DeleteAllPropOf(Product p)
        {
            foreach (var prop in DatabaseContext.DB.ProductProperties.Where(pr => pr.Product.Id == p.Id).ToList())
            {
                DatabaseContext.DB.ProductProperties.Remove(prop);
            }
            DatabaseContext.DB.SaveChanges();
        }

        public static string GetValueOf(Property pr, Product product)
        {
            var rs = DatabaseContext.DB.ProductProperties.Where(p => p.Product.Id == product.Id && p.Property.Id == pr.Id).ToList();
            if (rs.Count > 0) return rs[0].Value;
            return "";
        }
    }
}
